#include <stdio.h>

#define ROWS 3
#define COLS 3

int sum2d(int rows, int cols, int ar[rows][cols]);

int main(void)
{
    int i, j;
    int rs = 3; 
    int cs = 10;
    int junk[ROWS][COLS] = {
        { 2, 4, 6, 8 },
        { 3, 5, 7, 9 },
        { 12, 10, 8, 6 }
    };

    int varr[rs][cs];

    for (i = 0; i < rs; i++)
        for (j = 0; j < cs; j++)
            varr[i][j] = i * j + j;
    
    printf("3X5 array\n");
    printf("Sum of all elements = %d\n", sum2d(ROWS, COLS, junk));

    printf("2X6 array\n");
    printf("Sum of all elements = %d\n", sum2d(ROWS - 1, COLS + 2, morejunk));

    printf("3X10 VLA\n");
    printf("Sum of all elements = %d\n", sum2d(rs, cs, varr));
    return 0;
}

int sum2d(int rows, int cols, int ar[rows][cols])
{
    int r;
    int c;
    int tot = 0;

    for (r = 0; r < row; r++)
        for (c = 0; c < clos; c++)
            tot += ar[r][c];
    return tot;
}